package com.xxx.modules.controller;;
import com.xxx.modules.service.DrugService;
import com.xxx.modules.entity.Drug;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import com.github.pagehelper.PageInfo;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
import com.xxx.modules.utils.Result;
import com.xxx.modules.utils.ResultUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * drug
 *
 * @author 北易航
 * @since 1.0.0 2023-02-05
 */
@RestController
@RequestMapping("/common/drug")
@Api(tags="drug")
public class DrugController {
    @Autowired
    private DrugService drugService;

    /**
    *  获取所有用药情况
    * @param pageNum
    * @param pageSize
    * @param drug
    * @return
    */

    @GetMapping("/getDrugInfo")
    @ApiOperation("获取所有用药情况")
    public Result getDrugInfo(Drug drug, @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                      @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize){
        PageInfo<Drug> data = drugService.selectDrugInfo(drug,pageNum,pageSize);
        return ResultUtil.success(1,"成功",data);
    }

    /**
    * 保存用药情况
    * @param drug
    * @return
    */
    @PostMapping("/saveDrugInfo")
    @ApiOperation("保存用药情况")
    public Result saveDrugInfo(@RequestBody Drug drug){
        drugService.saveDrugInfo(drug);
        return ResultUtil.success(1,"成功",null);
    }


    /**
     * 更新用药情况
     * @param drug
     * @return
     */

    @PutMapping("/updateDrugInfo")
    @ApiOperation("更新用药情况")
    public Result updateDrugInfo(@RequestBody Drug drug){
        drugService.updateDrugInfo(drug);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id删除用药情况
     * @param id
     * @return
     */
    @DeleteMapping("/delDrugInfo")
    @ApiOperation("根据id删除用药情况")
    public Result delDrugInfo(Integer id){
        drugService.delDrugInfo(id);
        return ResultUtil.success(1,"成功",null);
    }

    /**
     * 根据id集合批量删除用药情况
     * @param idList
     * @return
     */
    @DeleteMapping("/delBatchDrugInfo")
    @ApiOperation("根据id集合批量删除用药情况")
    public Result delBatchDrugInfo(String idList){
        drugService.delBatchDrugInfo(idList);
        return ResultUtil.success(1,"成功",null);
    }

}